﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.Drawing;
namespace UTLCOMMAND
{
    public class UTLCommand
    {
        string _decimal;
        string _thousand;
        public UTLCommand() {
      //      strPath = ConfigurationManager.AppSettings["PathLogDefault"].ToString();
        }
        /// <summary>
        /// Định dạng tiền tệ
        /// </summary>
        /// <param param name="strMoney">Chuỗi tiền tệ cần định dạng</param>
        public string FormatMoney(string strMoney, string Unit)
        {
            string result = null;
            string[] deci;
            //string[] thousand;
            int num = 0;
            int i = 0;
            deci = strMoney.Split('.');
            if (deci[0].Length > 3)
            {
                i = deci[0].Length % 3;
                num = deci[0].Length / 3;
                if (i != 0)
                {
                    result = deci[0].Substring(0, int.Parse(i.ToString()));
                    result += ",";
                }
            }
            for (int j = 1; j <= num; j++)
            {
                result += deci[0].Substring(int.Parse(i.ToString()), 3);
                if (j != num)
                    result += ",";
                i += 3;
            }
            result += ".00";
            return result;
        }
        public string GetDat_MMDDYYYY(DateTime date) {
            string strdate = null;
            strdate = date.Day + "/" + date.Month + "/" + date.Year;
            return strdate;
        }
        public string EnCodeStringSHA1(string str)
        { 
            SHA1 sha1 = new SHA1CryptoServiceProvider();
            UTF8Encoding textConverter = new UTF8Encoding();
            byte[] passBytes = textConverter.GetBytes(str);
            return Convert.ToBase64String(sha1.ComputeHash(passBytes));
        }
        public string SplitExpression(string strSource,string strExpression)
        {
            return strSource.Replace(strExpression, "");
        }
        public static string CreateNameFileByDate()
        {
            string rs = "";
            string day = DateTime.Now.Day.ToString();
            if (DateTime.Now.Day < 10)
            {
                day = "0" + day;
            }
            string month = DateTime.Now.Month.ToString();
            if (DateTime.Now.Month < 10)
            {
                month = "0" + month;
            }
            rs = day + month + DateTime.Now.Year.ToString();
            return rs;
        }
        public static string GetRootAppPath()
        {
            return System.Windows.Forms.Application.StartupPath;
        }
        public static Image ByteArrayToImage(byte[] bytes)
        {
            if (bytes != null)
            {
                System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes);
                return Bitmap.FromStream(stream);
            }
            else
            {
                return null;
            }
        }
        public static byte[] ImageToByteArray(Image image)
        {
            if (image != null)
            {
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                return stream.ToArray();
            }
            else
            {
                return null;
            }
        }



    }
}
